// pages/orderDetail/orderDetail.js
const app = getApp();
import {
  showToast
} from '../../utils/util';
import {
  postRequest,
  getRequest,
  postParamsRequest
} from '../../api/request';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    themeColor: app.globalData.themeColor,
    subColor: app.globalData.subColor,
    btnColor: app.globalData.btnColor,
    baseImg: app.globalData.myTestImg,
    paymentPriority: wx.getStorageSync('paymentPriority') || 0, //0先付后吃  1先吃后付
    orderInfo: false,
    funIndex: 0, //功能
    payType: 1, //支付方式
    userInfo: {}, //用户信息
    payAmt: 0, //实付金额
    submitClose: true, //是否不允许提交订单
    payDiscountType: 0, //仅限储值支付享受会员
    orderId: "",
    submitLock: false, //提交锁
    showPay: false,
    technicalSupportIcon: '',
    couponList: [], //优惠券
    useCouponList: [], //可用优惠券
    showCouponList: false, //优惠券弹窗
    memberCouponId: [], //选中优惠券id
    memberEquityCardId: '', //选中权益卡
    showEquityCardList: false, //权益卡弹窗
    equityCardList: [], //权益卡
    useEquityCardList: [], //可用权益卡
    payTypeArr: [{
        id: 1,
        name: '微信',
      },
      {
        id: 4,
        name: '会员余额',
      },
    ],
    pindex: 0, //模板索引
    funIndex: 0, //功能

    boxAmt: 0, //餐盒费
    coverChargeAmt: 0, //茶位费
    deliveryAmt: 0, //配送费
    discountAmt: 0, //优惠金额
    equityCardDiscountAmt: 0, //权益卡优惠金额
    payAmt: 0, //实付金额
    serviceChargeAmt: 0, //服务费
    totalAmt: 0, //商品合计
    vipDiscountAmt: 0, //会员折扣
    deliveryOrderId: 0, //配送订单ID
    shopAndMykm: 0, //店铺和我的直线距离

    goodsList: [],
    orderType: 2, //订单类型：1-外卖，2-堂食，3-服务员点餐,4-自取，
    rechargeDiscountRule: [], //会员充值
    newGoodsList: [], //预付款订单商品
    options: {},
    useMemberVipDiscount: 1, //是否选择会员折扣
    showVipCoupon: false, //折扣选择弹窗
    useVipCheck: true, //选择使用会员

  },
  handVip(e) {
    console.log('e', e)
    if (e.detail.value.length) {
      console.log('jinlaile')
      this.setData({
        useVipCheck: true,

      })
    } else {
      this.setData({
        useVipCheck: false,

      })
    }

    console.log('useVipCheck', this.data.useVipCheck)
  },
  sureShowVipBtn() {
    // console.log('user',this.data.useVipCheck)
    if (this.data.useVipCheck) {
      this.setData({
        showVipCoupon: false,
        useMemberVipDiscount: 1,
        memberCouponId: [],
        memberEquityCardId: []
      })
    } else {
      this.setData({
        showVipCoupon: false,
        useMemberVipDiscount: 0,

      })
    }

    //重新计算订单
    this.getPreOrder(false, true);
  },
  //前往充值页面
  toStoredValuePage() {
    wx.navigateTo({
      url: '../storedValue/storedValue',
    })
  },
  //获取会员配置
  getMemberConfig() {
    let that = this;
    return new Promise(function (resolve, reject) {
      getRequest("/api/vip/member/config", {}).then((res) => {
        console.log(res.data.data);
        if (res.data.data != null) {
          let rule = res.data.data.rechargeDiscountRule == '' ? [] : JSON.parse(res.data.data.rechargeDiscountRule);
          that.setData({
            rechargeDiscountRule: rule,
            payDiscountType: res.data.data.payDiscountType
          });
        }
        resolve(res);
      }).catch((err) => {
        reject(err);
      });
    })
  },
  //功能选择
  bindPickerChangePrint(e) {
    let type = this.data.payTypeArr[e.detail.value].id
    this.setData({
      payType: type,
      funIndex: e.detail.value,
    });
    console.log('eeee', e)
    //储值支付时,如果余额不足不能提交订单
    if (this.data.payType == 4) {
      if (this.data.userInfo.cardRemaining * 1 < this.data.payAmt) {
        this.setData({
          submitClose: true,
        })
      }
    } else {
      this.setData({
        submitClose: false,
      })
    }
    this.surePayModal()


  },
  //获取个人信息
  getUserBaseInfo() {
    let that = this;
    wx.showLoading({
      title: "加载中...",
      icon: "none"
    });
    return new Promise(function (resolve, reject) {
      getRequest("/api/vip/getUserBaseInfo", {
        memberId: app.myInfo.memberId
      }).then((res) => {
        console.log(res.data.data);
        if (res.data.data != null) {
          wx.setStorageSync('userInfo', res.data.data);
          that.setData({
            userInfo: res.data.data,
          })
        }
        wx.hideLoading();
        resolve(res);
      }).catch((err) => {
        wx.hideLoading();
        reject(err);
      });
    });
  },

  //获取订单详情
  getFoodsOrderDetail(orderId) {
    wx.showLoading({
      title: '加载中...',
      icon: 'none'
    })
    getRequest("/api/vip/getFoodsOrderDetail", {
      orderId: orderId
    }).then((res) => {
      console.log("getFoodsOrderDetail", res.data.data);

      let cartList = res.data.data.orderGoods;
      let cartList2 = [];
      cartList.forEach((item, index) => {

        item.id = item.id;
        item.count = item.goodsNum;
        item.cateId = item.goodsCateId;
        item.goodsId = item.goodsId;
        if (item.isPresent != 1) {
          cartList2.push(item)
        }



      });
      // app.globalData.orderId = res.data.data.id;
      this.setData({
        orderInfo: res.data.data,
        goodsList: res.data.data.orderGoods,
        newGoodsList: cartList2,
        totalAmt: res.data.data.goodsPrice,
        payAmt: res.data.data.orderPrice,
        discountAmt: res.data.data.discountPrice
      });
      console.log('cartList2cartList2cartList2cartList2cartList2',cartList2)
      if (res.data.data.orderStatus == 0) {
        this.getPreOrder(true, true)
      }


      wx.hideLoading();
    }).catch((err) => {
      wx.hideLoading();
    });
  },

  //复制订单编号
  copyOrderSn(e) {
    wx.setClipboardData({
      data: e.currentTarget.dataset.sn,
      success: function (res) {
        wx.showToast({
          title: '复制成功',
          icon: 'none'
        })
      }
    });
  },

  //电话联系门店
  callPhone(e) {
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.phone,
      success: function () {
        console.log("拨打电话成功！")
      },
      fail: function () {
        console.log("拨打电话失败！")
      }
    })
  },

  //到这去，打开导航
  opLocations() {
    let arr = this.data.orderInfo.shopInfo.lnglat.split(',')
    const latitude = Number(arr[1])
    const longitude = Number(arr[0])
    wx.openLocation({
      latitude,
      longitude,
      name: this.data.orderInfo.shopInfo.shopName,
      address: this.data.orderInfo.shopInfo.address,
      scale: 18
    })
  },
  // 加菜ordertype
  addFoodsBtn() {
    wx.switchTab({
      url: '../scanMenu/scanMenu?orderType=5&addBtn=true'
    })
    app.globalData.addBtn = true;
    app.globalData.deskName = this.data.orderInfo.deskName;
    app.globalData.orderType = 5;
    app.globalData.paymentPriority = 1;
    app.globalData.orderId = this.data.orderInfo.id;
    app.globalData.deskId = '';
    // wx.setStorageSync('addBtnFoods', false)

  },
  showPayModal() {
    this.setData({
      showPay: true
    })

  },
  // 
  hidePayModal() {
    this.setData({
      showPay: false
    })
  },
  surePayModal() {
    let self = this;
    wx.showLoading({
      title: "提交中...",
      icon: "none",
      mask: true,
    });
    console.log(this.data.orderType, this.data.payType)
    // return
    //判断是微信支付还是储值
    if (this.data.payType == 1) {
      postParamsRequest("/api/order/payEatFoodsOrder", {
        orderId: this.data.orderId,
      }).then((res2) => {
        console.log(res2.data.data);
        let data = res2.data.data;
        wx.requestPayment({
          'timeStamp': data.timeStamp,
          'nonceStr': data.nonceStr,
          'package': data.package,
          'signType': data.signType,
          'paySign': data.paySign,
          'success': function (res3) {
            console.log(res3);
            wx.hideLoading();
            self.setData({
              isPay: true,
              showPay: false,
            })
            app.globalData.orderId = "";
            app.globalData.deskId = "";
            app.globalData.already = true;

            wx.clearStorageSync("deskName")
            wx.clearStorageSync('deskCode')
            wx.clearStorageSync('deskId')
            wx.clearStorageSync('orderId')
            // wx.clearStorageSync('paymentPriority')
            //支付成功跳转订单详情页
            wx.showToast({
              title: '支付成功',
              icon: 'success',
              success() {
                setTimeout(function () {

                  //要延时执行的代码
                  self.onLoad(app.globalData?.options)
                }, 2000) //延迟时间 

              }
            })
          },
          'fail': function (err) {
            console.log(err);
            wx.hideLoading();
            self.setData({
              submitLock: false,
              showPay: false,
            })

            //支付成功跳转订单详情页
            wx.showToast({
              title: '支付失败...',
              icon: 'error',
              success: function () {
                console.log("shibeibeiee")
                // 显示成功后的回调函数
                // wx.navigateBack()
                self.onLoad(app.globalData?.options)
              },
              fail: function () {
                // 显示失败后的回调函数
              }
            })
          }
        })

      }).catch((err) => {
        wx.hideLoading();
        self.setData({
          submitLock: false,
          showPay: false,
        })
      });
    } else {
      app.globalData.orderId = "";
      if (this.data.userInfo.cardRemaining * 1 < this.data.totalAmt) {
        wx.showToast({
          title: '储值余额不足',
          icon: 'error',

        })

      } else {
        if (this.data.useMemberVipDiscount) {
          postParamsRequest("/api/order/useVipDiscount ", {
            orderId: this.data.orderId,
            memberId: app.myInfo.memberId,

          }).then(vip => {
            console.log('vip', vip)
          })
        }
        // if(this.data.memberEquityCardId){
        //   postParamsRequest("/api/order/useVipDiscount ", {
        //     orderId: this.data.orderId,
        //     memberId: app.myInfo.memberId,

        //   }).then(vip => {
        //     console.log('vip', vip)
        //   })
        // }
        postParamsRequest("/api/order/balancePayOrder", {
          orderId: this.data.orderId,
          memberId: app.myInfo.memberId,
          beid: app.beid,
          orderType: 2,
          payType: 4
        }).then((res2) => {
          console.log("res2.data.data", res2.data.data);
          let data = res2.data.data
          if (data) {
            app.globalData.orderId = "";
            app.globalData.deskId = "";
            app.globalData.already = true;

            wx.clearStorageSync("deskName")
            wx.clearStorageSync('deskCode')
            wx.clearStorageSync('deskId')
            wx.clearStorageSync('orderId')
            // wx.clearStorageSync('paymentPriority')
            //支付成功跳转订单详情页
            wx.showToast({
              title: '储值支付成功',
              icon: 'success',
              duration: 2000,
              success() {
                setTimeout(function () {
                  //要延时执行的代码
                  self.onLoad(app.globalData?.options)
                }, 2000) //延迟时间 
              }
            })
          } else {
            wx.showToast({
              title: '储值支付失败',
              icon: 'error',
              success: function () {
                setTimeout(function () {
                  //要延时执行的代码
                  self.onLoad(app.globalData?.options)
                }, 2000) //延迟时间 
              },
              fail: function () {
                // 显示失败后的回调函数
              }
            })
          }


        }).catch((err) => {
          wx.hideLoading();
          self.setData({
            submitLock: false,
            showPay: false,
          })
        });

      }


      self.setData({
        submitLock: false,
        showPay: false,
      })
    }
  },
  //打开优惠券弹窗
  openShowCouponList() {
    if (this.data.couponList.length == 0) {
      return;
    }
    this.setData({
      showCouponList: true,
    });
  },
  //点击可用优惠券时
  onCouponSelect(e) {
    let cIndex = e.currentTarget.dataset.index;
    console.log(e);
    if (this.data.couponList[cIndex].isCanUse == 0) {
      return;
    }
    for (let i = 0; i < this.data.couponList.length; i++) {
      if (i == cIndex) {
        this.data.couponList[cIndex].checked = !this.data.couponList[cIndex].checked;
      } else {
        this.data.couponList[i].checked = false;
      }
    }
    this.upDateCoupon(this.data.couponList);
  },
  //选中的优惠券
  upDateCoupon(couponList) {
    if (this.data.memberEquityCardId != "") {
      wx.showToast({
        title: '优惠券和权益卡不能同时使用',
        icon: 'none'
      });
      return false;
    }
    let memberCouponId = [];
    couponList.forEach((item, index) => {
      if (item.checked) {
        memberCouponId.push(item);
      }
    });

    this.setData({
      couponList: couponList,
      memberCouponId: memberCouponId,

    })
    if (this.data.memberCouponId.length) {
      this.setData({
        useMemberVipDiscount: 0
      })
    } else {
      this.setData({
        useMemberVipDiscount: 1
      })
    }
    console.log('memberCouponId', this.data.memberCouponId.length)
    console.log('useMemberVipDiscount', this.data.useMemberVipDiscount)
  },
  //选择优惠券时
  onCouponCheck(e) {
    console.log(this.data.couponList)
    for (let i = 0; i < this.data.couponList.length; i++) {
      if (e.detail.value.indexOf(this.data.couponList[i].memberCouponId.toString()) != -1) {
        //判断是否可共用
        if (this.data.memberCouponId.length != 0) {
          if (this.data.memberCouponId[0].isMutex == 0) {
            if (this.data.couponList[i].isMutex == 1) {
              wx.showToast({
                title: '该券不可共用',
                icon: "none",
              })
              this.data.couponList[i].checked = false;
              this.upDateCoupon(this.data.couponList);
              return;
            }
          } else {
            wx.showToast({
              title: '该券不可共用',
              icon: "none",
            })

            this.upDateCoupon(this.data.couponList);
            return;
          }
        }

        this.data.couponList[i].checked = true;
      } else {
        this.data.couponList[i].checked = false;
      }
    }
    //选中的优惠券
    this.upDateCoupon(this.data.couponList);
  },
  //获取优惠券,可用优惠券
  getMemberCoupon() {
    let that = this;
    let param = {
      beid: app.beid,
      memberId: app.myInfo.memberId,
      goodsList: that.data.goodsList,
      orderType: that.data.orderType,
      totalAmt: that.data.totalAmt,
    };
    postRequest("/api/coupon/getPrePayCoupon", param).then((res) => {
      console.log(res.data.data);
      if (res.data.data != null) {
        //赋值为未选，并区分可选不可选
        let couponList1 = [];
        let couponList2 = [];
        res.data.data.forEach((item, index) => {
          item.checked = false;
          if (item.isCanUse) {
            couponList1.push(item);
          } else {
            couponList2.push(item);
          }
        });
        that.setData({
          couponList: couponList1.concat(couponList2),
          useCouponList: couponList1,
        });
      }
    }).catch((err) => {});
  },
  //获取权益卡,可用权益卡
  getPrePayEquityCardOrder() {
    let that = this;
    let param = {
      beid: app.beid,
      memberId: app.myInfo.memberId,
      goodsList: that.data.goodsList,
      orderType: that.data.orderType,
      totalAmt: that.data.totalAmt,
      // coverCharge:10,
      numberPeople: wx.getStorageSync('peopleNumber') || 0
    };
    postRequest("/api/activity/getPrePayEquityCardOrder", param).then((res) => {

      if (res.data.data != null) {
        //赋值为未选，并区分可选不可选
        let equityCard1 = [];
        let equityCard2 = [];
        res.data.data.forEach((item, index) => {
          //判断使用默认图片
          if (item.cardThumb == '') {
            if (item.cardType == 1) {
              item.cardThumb = that.data.myEqCord1;
            } else if (item.cardType == 2) {
              item.cardThumb = that.data.myEqCord2;
            } else if (item.cardType == 3) {
              item.cardThumb = that.data.myEqCord3;
            } else if (item.cardType == 4) {
              item.cardThumb = that.data.myEqCord4;
            } else if (item.cardType == 5) {
              item.cardThumb = that.data.myEqCord5;
            }
          }
          item.checked = false;
          if (item.status == 1) {
            equityCard1.push(item);
          } else {
            equityCard2.push(item);
          }
        });
        that.setData({
          equityCardList: equityCard1.concat(equityCard2),
          useEquityCardList: equityCard1,
        });
      }
    }).catch((err) => {});
  },
  //关闭优惠券弹窗
  hideShowCouponList() {
    this.setData({
      showCouponList: false,
    });
  },
  //确认权益卡
  sureEquityCardId() {
    this.setData({
      showEquityCardList: false,
    });
    //重新计算订单
    this.getPreOrder(false, true);
  },
  //打开权益卡弹窗
  openShowEquityCardList() {
    if (this.data.equityCardList.length == 0) {
      return;
    }
    this.setData({
      showEquityCardList: true,
    });
  },

  //关闭权益卡弹窗
  hideEquityCardList() {
    this.setData({
      showEquityCardList: false,
    });
  },
  //选择权益卡时
  onEquityCardCheck(e) {
    console.log(this.data.equityCardList)
    for (let i = 0; i < this.data.equityCardList.length; i++) {
      if (e.detail.value.indexOf(this.data.equityCardList[i].memberEquityCardId.toString()) != -1) {
        this.data.equityCardList[i].checked = true;
      } else {
        this.data.equityCardList[i].checked = false;
      }
    }
    //选中的权益卡
    this.upDateEquityCard(this.data.equityCardList);
  },
  //选中的权益卡
  upDateEquityCard(equityCardList) {

    if (this.data.memberCouponId != "") {
      wx.showToast({
        title: '权益卡和优惠券不能同时使用',
        icon: 'none'
      });
      return false;
    }
    let memberEquityCardId = '';
    let memberEquityCardIdList = [];
    equityCardList.forEach((item, index) => {
      if (item.checked) {
        memberEquityCardId = item.memberEquityCardId;
        memberEquityCardIdList.push(item.memberEquityCardId)
      }
    });
    this.setData({
      equityCardList: equityCardList,
      memberEquityCardId: memberEquityCardId,
      useMemberVipDiscount: 0
    })
    if (memberEquityCardIdList.length) {
      this.setData({
        useMemberVipDiscount: 0
      })
    } else {
      this.setData({
        useMemberVipDiscount: 1
      })
    }
    console.log('memberEquityCardIdList', memberEquityCardIdList)

  },
  hideShowVipCoupon() {
    this.setData({
      showVipCoupon: false,
    });
  },
  showVipCouponPrice() {
    this.setData({
      showVipCoupon: true
    })
  },
  //确认优惠券
  sureCouponId() {
    this.setData({
      showCouponList: false,

    });
    //重新计算订单
    this.getPreOrder(false, true);
  },
  //确认订单，isRefreshCoupon:是否获取优惠券，isPayType是否初始化支付方式
  getPreOrder(isRefreshCoupon, isPayType) {
    console.log('this.data.goodsList', this.data.orderInfo)
    this.setData({
      submitClose: true
    })
    //重新获取优惠券时把选择清空
    if (isRefreshCoupon) {
      this.setData({
        memberCouponId: [],
      });
    }
    let memberCouponId = [];
    let distance_new2 = 0;
    this.data.memberCouponId.forEach((item, index) => {
      memberCouponId.push(item.memberCouponId);
    });

    let param = {
      beid: app.beid,
      deliveryOrderId: this.data.deliveryOrderId, //配送订单ID(结算商品接口返回)
      goodsList: this.data.newGoodsList,
      memberCouponId: memberCouponId.join(","),
      cardId: this.data.memberEquityCardId,
      memberId: app.myInfo.memberId,
      numberPeople: wx.getStorageSync('peopleNumber') || 0,
      orderType: this.data.orderType,
      km: '',
      memberAddressId: '',
      payType: this.data.payType,
      useMemberVipDiscount: this.data.useMemberVipDiscount,
    };
    //外卖时传公里数和地址id
    if (this.data.orderType == 1) {
      if (this.data.deliveryInfo == null) {
        wx.showToast({
          title: '商家后台未设置外卖设置',
          icon: 'none'
        })
        return;
      }
      if (this.data.orderAddress == '') {
        wx.showToast({
          title: '请选择收货地址',
          icon: 'none'
        })
        return;
      }
      if (this.data.shopInfo.lnglat == undefined || this.data.shopInfo.lnglat == '') {
        wx.showToast({
          title: '商家门店设置未设置位置',
          icon: 'none'
        })
        return;
      }

      distance_new2 = this.getDistance2(Number(this.data.orderAddress.lnglat.split(',')[0]), Number(this.data.orderAddress.lnglat.split(',')[1]), Number(this.data.shopInfo.lnglat.split(',')[0]), Number(this.data.shopInfo.lnglat.split(',')[1]));
      console.log(distance_new2);
      // console.log(this.data.orderAddress);
      // console.log(this.data.shopInfo);
      if (distance_new2 > this.data.deliveryInfo.radiusRange * 1) {
        wx.showModal({
          title: '提示',
          content: '收货地址超过配送范围',
          showCancel: false
        })
        return;
      }

      param.km = distance_new2
      param.memberAddressId = this.data.orderAddress.id;
    }
    console.log(param);
    wx.showLoading({
      title: "加载中...",
      icon: "none"
    });
    postRequest("/api/order/getPreOrder", param).then((res) => {
      console.log(res.data.data);
      let data = res.data.data;
      //如果有余额，默认使用会员余额支付
      if (isPayType) {
        if (this.data.userInfo.cardRemaining * 1 >= data.payAmt * 1) {
          this.setData({
            payType: 4,
          });
          if (this.data.payDiscountType == 1) {
            this.getPreOrder(true, false);
          }
        } else {
          this.setData({
            payType: 1,
          });
        }
      }

      if (data.payAmt == 0) {
        this.setData({
          payType: 8,
        });
      }


      this.setData({
        boxAmt: data.boxAmt, //餐盒费
        coverChargeAmt: data.coverChargeAmt, //茶位费
        deliveryAmt: data.deliveryAmt, //配送费
        discountAmt: data.discountAmt, //优惠金额
        equityCardDiscountAmt: data.equityCardDiscountAmt, //权益卡优惠金额
        payAmt: data.payAmt, //实付金额
        serviceChargeAmt: data.serviceChargeAmt, //服务费
        totalAmt: data.totalAmt, //商品合计
        vipDiscountAmt: data.vipDiscountAmt, //会员折扣
        deliveryOrderId: data.deliveryOrderId, //配送订单ID(结算商品接口返回)
        shopAndMykm: distance_new2, //店铺和我的直线距离
        submitClose: false
      });

      //储值支付时,如果余额不足不能提交订单
      if (this.data.payType == 4) {
        if (this.data.userInfo.cardRemaining * 1 < this.data.payAmt) {
          this.setData({
            submitClose: true,
          })
        }
      }

      if (app.globalData?.paymentPriority == 1 || wx.getStorageSync('paymentPriority') == 1) {
        this.setData({
          payType: 1
        })
      }
      //获取可用优惠券
      if (isRefreshCoupon) {
        this.getMemberCoupon();
        this.getPrePayEquityCardOrder();
      }


      wx.hideLoading();
    }).catch((err) => {
      this.setData({
        submitClose: false
      })
      wx.hideLoading();
    });
  },
  //支付方式改变
  onPayTypeChange(e) {
    this.setData({
      payType: e.currentTarget.dataset.type,
    });
    console.log('eeee', e)
    //储值支付时,如果余额不足不能提交订单
    if (this.data.payType == 4) {
      if (this.data.userInfo.cardRemaining * 1 < this.data.payAmt) {
        this.setData({
          submitClose: true,
        })
      }
    } else {
      this.setData({
        submitClose: false,
      })
    }
    // if (this.data.payDiscountType == 1) {
    //   this.getPreOrder(false, false);
    // }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log('this.data.orderTypeononLoad', this.data.orderType)
    console.log('app.globalData?.paymentPriority', app.globalData?.paymentPriority)
    console.log('app.globalData?.addBtn', app.globalData?.addBtn)
    console.log('app.globalData.orderType', app.globalData.orderType)
    console.log('app.globalData?.orderId', app.globalData?.orderId)
    console.log('app.globalData.orderType ', app.globalData.orderType)
    app.globalData.options = options;
    console.log("options", options);
    if (options?.orderType) {
      this.setData({
        orderType: options.orderType
      })
    }
    //技术支持图片
    var imgIcon = wx.getStorageSync('shopInfo');
    if (imgIcon != undefined && imgIcon != '') {
      console.log(imgIcon);
      this.setData({
        technicalSupportIcon: imgIcon.technicalSupportIcon,
        // isOpenRetention: imgIcon.isOpenRetention,
        // isPlaceOrder: imgIcon.isPlaceOrder, //是否可以预约下单
      })
    }
    //获取订单详细信息
    if (options.orderId != '' && options.orderId != undefined) {
      this.setData({
        orderId: options.orderId
      })
      //如果没有token,则需要重新登录获取个人信息等，避免缺少id导致数据无法获取
      if (app.token == "" || app.token == undefined) {
        app.initLogin().then(res => {
          this.getFoodsOrderDetail(options.orderId);
        }).catch(err => {})
      } else {

        this.getUserBaseInfo();
        this.getFoodsOrderDetail(options.orderId);
        console.log('paymentPrioritypaymentPrioritypaymentPrioritypaymentPrioritypaymentPriority', wx.getStorageSync('paymentPriority'))
        // if (wx.getStorageSync('paymentPriority') == 1) {

        // } 
        this.getMemberConfig();

      }
    }

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})